/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>Project: jse2303 - Set1
 * <p>Powered by webrx On 2023-07-19 15:49:15
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Set1 {
    public static void main(String[] args) {
        //Set set = new HashSet();
        //实例化对象 元素是唯一的，不能有重复对象
        Set<String> set = new HashSet<>();

        //添加元素
        set.add("java");
        set.addAll(List.of("javascript", "php", "c", "php", "php", "python"));
        set.add("php");

        //删除
        //set.clear(); 清空
        //set.remove("java"); //删除存在的返回true
        //set.removeAll(List.of("php", "c"));

        //删除不存在的，返回false
        //set.remove("java");

        //检查
        //System.out.println(set.contains("php"));
        //System.out.println(set.containsAll(List.of("php", "java")));

        //遍历
        System.out.println(set);
        for (String str : set) {
            System.out.println(str);
        }

        //输出set集合元素个数
        System.out.println(set.size());
    }
}
